	function mgfrcalc(unitchoice,sex,race,age,creatinine,idms){

	
	var mgfr=0;
	var sconstant=1;
	var rconstant =1.212;
	var multiplier = 186;
	
//convert SI to US
if (unitchoice){
creatinine=creatinine/88.4;
}	
	
	
// MDRD Modification of Diet in Renal Disease Study Group Equation
// mgfr = 186.3 x SerumCr^-1.154 * age^-0.203 * 1.21?0/2 (if patient is black) * 0.742 (if female) 

if (sex==0){
sconstant = 0.742;
}

if (race==0){
rconstant = 1;
}

if (idms==1){
multiplier = 175;
}



mgfr=multiplier * (Math.pow(age,-0.203)) * (Math.pow(creatinine,-1.154)) * sconstant * rconstant;


//convert back to SI 
if (!unitchoice){
creatinine=creatinine*88.4;
}	

//round up
mgfr=Math.round(mgfr*100)/100;   
creatinine=Math.round(creatinine);			


return {
			 mgfr:mgfr,
			 age:age,
			 creatinine:creatinine
	};		 
}




function ref(){
// display reference
 return "A.S. Levey, T. Greene, J.W. Kusek, G.L. Beck, MDRD Study Group. A simplified equation to predict glomerular filtration rate from serum creatinine (abstract) J Am Soc Nephrol 2000 Sep; 11:155A";

}

function help(){
// display help
 return "This score is only for chronic kidney disease and is not accurate for acute renal failure. A <a href=\"http://www.annals.org/cgi/content/abstract/141/12/929\">recent study</a> indicates the MDRD may underestimate the actual GFR in healthy patients by up to 29%." +"<br />Recalibrated creatinine (IDMS) means your lab uses a creatinine method that has been standardized or traceable to isotope dilution mass spectrometry";

}

